package com.study.talk.ui.app.moment

import android.app.Application
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.study.common.ToastUtil
import com.study.talk.ui.app.base.BaseViewModel
import com.study.talk.data.model.resp.MomentResponse
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class MomentsViewModel @Inject constructor(application: Application) : BaseViewModel(application) {
    private val _moments = MutableLiveData<List<MomentResponse>>()
    val moments get() = _moments

    fun getMoments(userId: Int) {
        viewModelScope.launch {
            momentRepository.getMoments(userId, success = {
                _moments.postValue(it)
            }, fail = { msg: String ->
                ToastUtil.showToast(app, msg)
            })
        }
    }

    fun getUserMoments(userId: Int) {
        viewModelScope.launch {
            momentRepository.getUserMoments(userId, success = {
                _moments.postValue(it)
            }, fail = { msg: String ->
                ToastUtil.showToast(app, msg)
            })
        }
    }
}